package org.algorithm.熊猫.数组.三月.第三周;

import org.junit.Test;

import java.util.Arrays;

/**
 * @Date 2022/3/13 23:32
 * @Created by biubiu
 * @Link {https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element/}
 */
public class 颜色分类 {


    @Test
    public void test() {
        int[] nus = {1, 2, 0};
        sortColors(nus);
        System.out.println(Arrays.toString(nus));
    }

    public void sortColors(int[] nums) {
        int index = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            int num = nums[i];
            if (num == 0) {
                nums[i] = nums[index];
                nums[index] = num;
                ++index;
            }
        }

        for (int i = index; i < n; i++) {
            int num = nums[i];
            if (num == 1) {
                nums[i] = nums[index];
                nums[index] = num;
                ++index;
            }
        }

    }
}
